package com.dbdata.move.service;

import com.dbdata.move.dao.StudentTypeDao;
import com.dbdata.move.model.StudentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Richard
 */
@Service
public class StudentTypeService {
    private static final Logger L = LoggerFactory.getLogger(StudentTypeService.class);

    @Autowired
    private StudentTypeDao dao;

    public Map<String, Long> getStuTypeAll() {
        List<StudentType> list = dao.list(StudentType.class);
        Map<String, Long> map = new HashMap<String, Long>(list.size());
        for (StudentType o : list) {
            if (map.containsKey(o.getTypeName())) {
                L.error("数据库存在相同的学生类型：{}", o.getTypeName());
            } else {
                map.put(o.getTypeName(), o.getId());
            }
        }
        return map;
    }
}
